#include <iostream>
#include "ReferenceManager.h"
#include "Reference.h"
#include "Thesis.h"
#include "TechReport.h"
#include "Report.h"
#include "Article.h"

using std::cout;
using std::endl;

int main (int argc, char * const argv[]) {
    cout << "Let's create 15 = 3 objects instance of each of the following classes: Reference, Thesis, TechReport, Report, Article" << endl;
    int idFirstRemoved, idSecondRemoved;
	Reference ref1,ref2,ref3;
	Thesis th1,th2,th3;
	TechReport tech1,tech2,tech3;
	Report rep1,rep2,rep3;
	Article art1,art2,art3;
	cout << "Then, let's create one instance of the ReferenceManager class: capacity set to 14 (and we'll try to add a 15th element to it later)" << endl; 
	ReferenceManager refMan(14);
	
	cout << "After that, let's set different identifiers for the 3 objects instance of each of the following classes: Reference, Thesis, TechReport, Article" << endl;
	ref1.setId(0); ref2.setId(1); ref3.setId(2);
	th1.setId(3); th2.setId(4); th3.setId(5);
	tech1.setId(6); tech2.setId(7); tech3.setId(8);
	rep1.setId(9); rep2.setId(10); rep3.setId(11);
	art1.setId(12); art2.setId(13); art3.setId(14);
	
	cout << "Size (number of elements) of refMan before adding anything is:"<<refMan.size()<<endl;
	cout << "Let us add the 14 first elements to the ReferenceManager" << endl;
	refMan.add(ref1); refMan.add(ref2); refMan.add(ref3);
	refMan.add(th1); refMan.add(th2); refMan.add(th3);
	cout << "->In the middle of the operation, we test that refMan.add returns true when adding one element (here it is the seventh one to be added)" << endl;
	cout << "because the list is not totally full and thus the element could be added" << endl;
	if(refMan.add(tech1))
		cout << "->as was expected, refMan's add method returned true" << endl;
	else
		cout << "->the program should be reworked ! refMan's add method did not return true (meaning the list is not full & element could be added) while it had to" << endl;
	
	refMan.add(tech2); refMan.add(tech3);
	refMan.add(rep1); refMan.add(rep2); refMan.add(rep3);
	refMan.add(art1); refMan.add(art2);
	cout << "Now that the list in refMan object is full: refMan.size()==14 is [evaluated_to:"<<(refMan.size()==14 ? "true" : "false")<<"], let's try to add a 15th element" << endl;
	if(!refMan.add(art3))
		cout << "->as was expected, refMan's add method returned false (& printed an error)" << endl;
	else
		cout << "->the program should be reworked ! refMan's add method did not return false (meaning its list is full) while it had to" << endl;
	
	cout << "Here are the Ids in the list:"<<endl;
	refMan.printIds();
	
	cout << "Now we remove the last element (size is refMan.size():[evaluated_to:"<<refMan.size()<<"] and position of the element to remove is 13)"<<endl;
	if(refMan.remove(13))
		cout << "->refMan.remove(13) returned true, so removal has worked, this is what we wanted" << endl;
	else
		cout << "->the program should be reworked ! was not able to remove an element that actually is in refMan's list"<<endl;
	cout << "Finally, the Ids in the list become:"<<endl;
	refMan.printIds();
	
	idFirstRemoved = refMan.get(3); idSecondRemoved = refMan.get(7+1);
	cout << "Removing some elements in the middle : elements at position 3 (id=refMan.get(3)="<<idFirstRemoved<<") and 7 (id=refMan.get(7)="<<idSecondRemoved<<" (testing the right shifting for Refman::remove(int):" << endl;
	refMan.remove(3);
	refMan.remove(7);
	cout << "Now Refman's items' ids are as follows:" << endl;
	refMan.printIds();
	cout << "Are elements with id " << idFirstRemoved << " and " << idSecondRemoved << " still in the list ? (id:" << idFirstRemoved << " " << (refMan.search(idFirstRemoved) ? "yes-PROBLEM" : "no") << " should be no) (id:"<< idSecondRemoved << " " << (refMan.search(idSecondRemoved) ? "yes-PROBLEM" : "no") << " should be no)" << endl;
	cout << "END OF TESTING EXECUTABLE" << endl;

#ifdef WIN32
 system("PAUSE");
#endif

	return 0;
}
